package com.laihui.activity;

import android.app.Activity;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;


import com.laihui.base.BaseActivity;
import com.laihui.fragment.AllMoneyDetailFragment;
import com.laihui.fragment.CashLogFragment;
import com.laihui.fragment.RechargeLogFragment;
import com.laihui.view.TopBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;


/**
 * Created by Administrator on 2018/1/4.
 */

public class AvailableCapitalActivity extends BaseActivity {

//    @BindView(R.id.tabs_available)
    TabLayout tabs_available;
//    @BindView(R.id.viewPager)
    ViewPager viewPager;

    @BindView(R.id.topbar)
    TopBar topbar;

    private List<String> mTitles = new ArrayList<>();
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    @Override
    public void init() {
        initViewPager();
    }

    private void initViewPager() {
        tabs_available =(TabLayout)findViewById(R.id.tabs_available);
        viewPager =(ViewPager)findViewById(R.id.viewPager);
        mFragments = getFragments();
        mTitles.add("总的");
        mTitles.add("充值");
        mTitles.add("提现");
        viewPager.setAdapter(new AvailableCapitalActivity.BorrowPagerAdapter(this.getSupportFragmentManager()));
        viewPager.setOffscreenPageLimit(3);
        tabs_available.setupWithViewPager(viewPager);
        topbar.setOnTopbarClickListener(new TopBar.topbarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {

            }
        });
    }
    @Override
    public int getLayoutId() {
        return R.layout.activity_available_capital;
    }

    private ArrayList<Fragment> getFragments() {
        ArrayList<Fragment> list = new ArrayList<>();
        list.add(new AllMoneyDetailFragment());
        list.add(new RechargeLogFragment());
        list.add(new CashLogFragment());
//        list.add(new BorrowListFragment(2));
        return list;
    }

    @Override
    public Activity bindActivity() {
        return this;
    }

    private class BorrowPagerAdapter extends FragmentPagerAdapter {

        public BorrowPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles.get(position);
        }
    }
}
